package background

import (
	"clouds.lgb24kcs.cn/errorx"
	"clouds.lgb24kcs.cn/global"
	"clouds.lgb24kcs.cn/models"
	"clouds.lgb24kcs.cn/utils"
	"fmt"
	"github.com/gin-gonic/gin"
)

type CarouselLists struct {
}

var CarouselListsApi CarouselLists

func (l *CarouselLists) Lists(c *gin.Context, userId int64) {
	lists := []models.Carousel{}
	var Count int64
	tx := global.APP.DB.Where("user_id=?", userId).Find(&lists).Count(&Count)
	if tx.Error != nil {
		global.APP.Log.Error(fmt.Sprintf("轮播图查询错误：%s", tx.Error))
		utils.Fail(c, errorx.CarouselList, fmt.Sprintf("轮播图查询错误：%s", tx.Error))
	} else if tx.RowsAffected == 0 {
		utils.Fail(c, errorx.CarouselList, fmt.Sprintf("没有轮播图数据"))
	} else {
		utils.Success(c, Count, lists)
	}
}
